package com.example.layoutdesignnet2034;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private  ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_view_layout);

       Button bt2 = findViewById(R.id.bt2);
        imageView =findViewById(R.id.imagev);
      Button change_img_bt = findViewById(R.id.change_img_bt);
      //更换图片的按钮的监听
      change_img_bt.setOnClickListener(this);
       //点击监听
       bt2.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               Log.i("TAG","bt2被点击了");
           }
       });

    }

    public void click(View view){
        Log.i("TAG","我被点击了~~~");
    }

    //实现View.OnClickListener的方法
    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.change_img_bt){//当点击更换图片按钮，实现更换图片资源的逻辑
            imageView.setImageResource(R.drawable.test2image);
        }

    }
}